//
// Created by ASUS on 24-4-18.
//

#include "SqQueue.h"


// 队头指针指向队头元素，队尾指针指向队尾元素，
void SqQueue_Init(SqQueue *q) {
    q->front = 0;
    q->rear = 0;
}

int SqQueue_Empty(SqQueue *q) {
    if(q->front == q->rear)
        return 1;
    return 0;
}

// 从队尾入队
int SqQueue_En(SqQueue *q, ElemType e) {
    if((q->rear+1)%MaxSize == q->front) {
        return -1;
    }
    q->data[q->rear] = e;
    q->rear = (q->rear+1)%MaxSize;
    return 1;
}

// 从对头出队
int SqQueue_De(SqQueue *q, int *e) {
    if(q->front == q->rear)
        return -1;
    *e = q->data[q->front];
    q->front = (q->front+1)%MaxSize;
    return 1;
}

// 查看对头元素
int SqQueue_GetHead(SqQueue *q, ElemType *e) {
    if(q->front == q->rear) {
        return -1;
    }
    *e = q->data[q->front];
    return 1;
}

void SqQueue_Print(SqQueue *q) {
    int i = q->front;
    printf("Queue: front ");
    while(i != q->rear) {
        printf("%d ", q->data[i]);
        i++;
    }
    printf("rear \n");
}
